﻿using Microsoft.VisualBasic.Devices;
using SanXiao.Game.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SanXiao.Game.GameCenter
{
    public unsafe abstract class GameObject : IDisposable, ICloneable
    {
        private Size _size;
        public GameObject(GameType gameType, Size size)
        {
            GameType = gameType;
            _size = size;
        }
        public GameType GameType { get; private set; }
        public Size Size { get { return _size; } private set { _size = value; } }
        public Point Location { get; set; }
        public int StartX { get; set; }
        public int StartY { get; set; }
        public int CellWidth { get; set; }
        public int CellHeight { get; set; }
        public float ZoomX { get; set; }
        public float ZoomY { get; set; }
        public int Row { get; set; }
        public int Column { get; set; }
        public int MaxRow { get; set; }
        public int MaxColumn { get; set; }
        public Rectangle Bounds => new Rectangle(Location.X, Location.Y, Size.Width, Size.Height);
        public bool IsBlock => this.GameType.GetHashCode() < GameType.SpecialEffects1.GetHashCode();
        public abstract void Draw(Graphics g);
        public virtual void Logic(GameObject* set) { }
        public virtual void MouseDown(GameObject* set) { }
        public virtual void UpdateState()
        {
            Location = new Point(StartX + Column * CellWidth, StartY + Row * CellHeight);
            Size = new Size((int)(Size.Width * ZoomX), (int)(Size.Height * ZoomY));
        }
        public void SizeChange(int row, int column, int startX, int startY, int cellWidth, int cellHeight, float zoomX, float zoomY)
        {
            ZoomX = zoomX;
            ZoomY = zoomY;
            CellWidth = cellWidth;
            CellHeight = cellHeight;
            MaxColumn = column;
            MaxRow = row;
            StartX = startX;
            StartY = startY;

            UpdateState();
        }
        public static ImageObject[] ToImageObjects(Bitmap[] bitmaps)
        {
            ImageObject[] images = new ImageObject[bitmaps.Length];
            for (int i = 0; i < images.Length; i++)
            {
                images[i] = new ImageObject(bitmaps[i]);
            }
            return images;
        }
        public void Dispose()
        {
            DisposeImage();
        }
        protected virtual void DisposeImage()
        {
        }

        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }
}
